//
//  btSecondViewController.m
//  isnmpp
//
//  Created by Yan Chiu on 12-08-09.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "snmp_pp.h"
#import <iostream.h>
#import <stdlib.h>

#import "btSecondViewController.h"

@interface btSecondViewController ()

@end

@implementation btSecondViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    GenAddress address( "192.168.0.106");
    Oid oid("1.3.6.1.2.1.1.1.0");
    
    snmp_version version=version2c;                       // default is v1
    int retries=1;                                       // default retries is 1
    int timeout=100;                                     // default is 1 second
    OctetStr community("public");                        // community name
    
    int status;
    Snmp snmp( status);
    Pdu pdu;                                // construct a Pdu object
    Vb vb;                                  // construct a Vb object
    vb.set_oid( oid);                       // set the Oid portion of the Vb
    pdu += vb;                              // add the vb to the Pdu
    CTarget target( address);               // make a target using the address
    target.set_version( version);           // set the SNMP version SNMPV1 or V2
    target.set_retry( retries);             // set the number of auto retries
    target.set_timeout( timeout);           // set timeout
    target.set_readcommunity( community);   // set read community
    target.set_writecommunity( community);// set the write community name
    
    //-------[ issue the request, blocked mode ]-----------------------------
    cout << "SNMP++ Get to " << "192.168.0.106" << " SNMPV" << (version+1) << " Retries=" << retries;
    cout << " Timeout=" << timeout <<"ms " << "Community=" << community.get_printable() << "\n";
    if (( status = snmp.get( pdu,target))== SNMP_CLASS_SUCCESS) {
        pdu.get_vb( vb,0);
        cout << "Oid = " << vb.get_printable_oid() << "\n";
        cout << "Value = " << vb.get_printable_value() << "\n";
    }
    else {
        cout << "SNMP++ Get Error, ";
        if ( status == SNMP_CLASS_ERR_STATUS_SET)
            status = pdu.get_error_status();
        cout << snmp.error_msg( status) << "\n";
    }
    

    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
